package cn.edu.zut.dao;

import cn.edu.zut.domin.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 *用户dao接口
 *
 */
public interface IUserDao {

    /**
     * 查询所有用户信息
     * @return
     * @throws Exception
     */
    @Select("select * from user")
    public List<User> findAll() throws Exception;

    /**
     * 根据账号查找用户
     * @param id
     * @return
     * @throws Exception
     */
    @Select("select * from user where id=#{id}")
    public User findById(String id) throws Exception;

    /**
     * 根据姓名查询用户信息
     * @param username
     * @return
     * @throws Exception
     */
    @Select("select * from user where username=#{username}")
    public List<User> findByUserName(String username) throws Exception;

    /**
     * 添加某个用户的信息
     * @param user
     * @throws Exception
     */
    @Insert("insert into user (id,password,userName,status) values (#{id},#{password},#{userName},#{status})")
    public void saveUser(User user) throws Exception;

    /**
     * 删除某个用户
     * @param id
     * @throws Exception
     */
    @Delete("delete from user where id=#{id}")
    public void deleteUserById(String id) throws Exception;

    /**
     * 更新用户信息
     * @param user
     * @throws Exception
     */
    @Update("update user set password=#{password},userName=#{userName},status=#{status} where id=#{id}")
    public void updateUser(User user) throws Exception;
}
